package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 攻略服务实现类
 *
 * @author totoro93
 * @date 2019-01-11
 **/
@Service
public class StrategyServiceImpl implements IStrategyService {

    @Autowired
    private StrategyMapper strategyMapper;

    @Override
    public PageInfo query(StrategyQueryObject queryObject) {
        //设置不进行合理化分页，避免出现当只有一页数据，获取第二页数据时返回第一页数据
        PageHelper.startPage(queryObject.getCurrentPage(), queryObject.getPageSize(),true,false,null);
        List<Strategy>list=strategyMapper.selectForList(queryObject);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId() != null) {
            strategyMapper.updateByPrimaryKey(strategy);
        } else {
            strategyMapper.insert(strategy);
        }
    }

    @Override
    public List<Strategy> listAll() {
        return strategyMapper.selectAll();
    }

    @Override
    public Strategy selectByStrategyId(Long id) {
        return strategyMapper.selectByPrimaryKey(id);
    }

}
